﻿using System;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Helpers;

namespace ASPNETVN.PORTAL.Modules.INTRODUCTION.Controls
{
    public enum ModulePages
    {
        Item
    }

    public partial class Main : PortalModuleControl
    {
        private void LoadChildControl()
        {
            const string basePath = "~/Modules/ASPNETVN.PORTAL.Modules.INTRODUCTION/";
            const string pageQuery = "page";
            string pageName = Request.QueryString[pageQuery];

            ModulePages page = ModulePages.Item;
            if (pageName != null)
            {
                page = (ModulePages)Enum.Parse(typeof(ModulePages), pageName, true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "AddEditItem");
            this.ModuleTitle.ManagerUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "ItemManager");
            this.LoadChildControl();
        }
    }
}